import Fetch, { Cookie } from '@wattjs/network'
import { message } from 'ant-design-vue'
import { APP_ID, BASE_URL, XSRF_HEADER, REQUEST_TIMEOUT } from './config'

const http = new Fetch({
  config: {
    APP_ID,
    BASE_URL,
    XSRF_HEADER,
    REQUEST_TIMEOUT
  },
  transformRequest: [(data, headers) => {
    const token = Cookie.get('token')
    if (token) Object.assign(headers, {
      'Authorization': `Bearer ${token}`
    })
    return data
  }],
  // withCredentials: true,
  showToast: (content) => {
    // 错误提示
    message.error({
      content,
      duration: 2.5
    })
  },
})

export default http
